﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;

namespace A2DFramework.EventService.SuperSocket.Core.Commands
{
    public class Subscribe : CommandBase<EventDispatcherBusSession, StringRequestInfo>
    {
        public override void ExecuteCommand(EventDispatcherBusSession session, StringRequestInfo requestInfo)
        {
            string classPath = Helper.RestoreSpecialCharacters(requestInfo.Parameters[0]);
            if (session.SubscribedEventClasses.Contains(classPath))
                return;

            session.SubscribedEventClasses.Add(classPath);

            string msg = "";
            msg+=string.Format("[{0}], now subscribed these events:\r\n", session.AssociatedServerIdentity);
            foreach(string evtClass in session.SubscribedEventClasses)
                msg += string.Format("              {0}\r\n", evtClass);
            Console.WriteLine(msg);
        }
    }
}
